package com.sjgs.gis.domain;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import javax.persistence.*;
import javax.validation.constraints.*;

import java.io.Serializable;
import java.time.Instant;
import java.util.HashSet;
import java.util.Set;

import com.sjgs.gis.domain.enumeration.NodeStatus;

/**
 * Node entity.\n@author The JHipster team.
 */
@Entity
@Table(name = "node")
public class Node implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
    @SequenceGenerator(name = "sequenceGenerator")
    private Long id;

    @NotNull
    @Column(name = "node_instance_id", nullable = false)
    private String nodeInstanceId;

    @NotNull
    @Column(name = "node_addr", nullable = false)
    private String nodeAddr;

    @NotNull
    @Column(name = "version", nullable = false)
    private String version;

    @NotNull
    @Column(name = "war_url", nullable = false)
    private String warUrl;

    @Column(name = "data_url")
    private String dataUrl;

    @Column(name = "create_time")
    private Instant createTime;

    @Enumerated(EnumType.STRING)
    @Column(name = "status")
    private NodeStatus status;

    @OneToMany(mappedBy = "node")
    private Set<NodePlugin> nodePlugins = new HashSet<>();

    @ManyToOne
    @JsonIgnoreProperties(value = "nodes", allowSetters = true)
    private JdbcCluster jdbcCluster;

    // jhipster-needle-entity-add-field - JHipster will add fields here
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNodeInstanceId() {
        return nodeInstanceId;
    }

    public Node nodeInstanceId(String nodeInstanceId) {
        this.nodeInstanceId = nodeInstanceId;
        return this;
    }

    public void setNodeInstanceId(String nodeInstanceId) {
        this.nodeInstanceId = nodeInstanceId;
    }

    public String getNodeAddr() {
        return nodeAddr;
    }

    public Node nodeAddr(String nodeAddr) {
        this.nodeAddr = nodeAddr;
        return this;
    }

    public void setNodeAddr(String nodeAddr) {
        this.nodeAddr = nodeAddr;
    }

    public String getVersion() {
        return version;
    }

    public Node version(String version) {
        this.version = version;
        return this;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getWarUrl() {
        return warUrl;
    }

    public Node warUrl(String warUrl) {
        this.warUrl = warUrl;
        return this;
    }

    public void setWarUrl(String warUrl) {
        this.warUrl = warUrl;
    }

    public String getDataUrl() {
        return dataUrl;
    }

    public Node dataUrl(String dataUrl) {
        this.dataUrl = dataUrl;
        return this;
    }

    public void setDataUrl(String dataUrl) {
        this.dataUrl = dataUrl;
    }

    public Instant getCreateTime() {
        return createTime;
    }

    public Node createTime(Instant createTime) {
        this.createTime = createTime;
        return this;
    }

    public void setCreateTime(Instant createTime) {
        this.createTime = createTime;
    }

    public NodeStatus getStatus() {
        return status;
    }

    public Node status(NodeStatus status) {
        this.status = status;
        return this;
    }

    public void setStatus(NodeStatus status) {
        this.status = status;
    }

    public Set<NodePlugin> getNodePlugins() {
        return nodePlugins;
    }

    public Node nodePlugins(Set<NodePlugin> nodePlugins) {
        this.nodePlugins = nodePlugins;
        return this;
    }

    public Node addNodePlugin(NodePlugin nodePlugin) {
        this.nodePlugins.add(nodePlugin);
        nodePlugin.setNode(this);
        return this;
    }

    public Node removeNodePlugin(NodePlugin nodePlugin) {
        this.nodePlugins.remove(nodePlugin);
        nodePlugin.setNode(null);
        return this;
    }

    public void setNodePlugins(Set<NodePlugin> nodePlugins) {
        this.nodePlugins = nodePlugins;
    }

    public JdbcCluster getJdbcCluster() {
        return jdbcCluster;
    }

    public Node jdbcCluster(JdbcCluster jdbcCluster) {
        this.jdbcCluster = jdbcCluster;
        return this;
    }

    public void setJdbcCluster(JdbcCluster jdbcCluster) {
        this.jdbcCluster = jdbcCluster;
    }
    // jhipster-needle-entity-add-getters-setters - JHipster will add getters and setters here

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof Node)) {
            return false;
        }
        return id != null && id.equals(((Node) o).id);
    }

    @Override
    public int hashCode() {
        return 31;
    }

    // prettier-ignore
    @Override
    public String toString() {
        return "Node{" +
            "id=" + getId() +
            ", nodeInstanceId='" + getNodeInstanceId() + "'" +
            ", nodeAddr='" + getNodeAddr() + "'" +
            ", version='" + getVersion() + "'" +
            ", warUrl='" + getWarUrl() + "'" +
            ", dataUrl='" + getDataUrl() + "'" +
            ", createTime='" + getCreateTime() + "'" +
            ", status='" + getStatus() + "'" +
            "}";
    }
}
